﻿@model IEnumerable<WaiGaoQiaoWeb.Models.ManualEntryVM>
@{
    ViewBag.Title = "ManualEntryIndex";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@section Head
{
    @Html.Css("EditForm", "RightSeparateModule", "dp")
    @Html.Js("datepicker")
    <script type="text/javascript" language="javascript">
        var maiheight = document.documentElement.clientHeight;
        var mainWidth = document.documentElement.clientWidth - 10; // 减去边框和左边的宽度
        $(document).ready(function () {
            $("#StartTime").datepicker({ picker: "<img class='picker' align='middle' src='../../Images/icons/s.gif' alt=''/>" });
            $("#EndTime").datepicker({ picker: "<img class='picker' align='middle' src='../../Images/icons/s.gif' alt=''/>" });
            var otherpm = $("#title").height() + $("#findDiv").height(); // 290;
            var gh = maiheight - otherpm - 80;
            var option = {
                height: gh,
                width: mainWidth,
                url: '@Url.Action("GetManualEntryList")', // 参数要放在）括号的外面
                dataType: 'json',
                colModel: [
                    { display: 'ID', name: 'ID', width: 70, sortable: false, hide: true, align: 'left', iskey: true },
                    { display: '日期', name: 'RDATETIME', width: 130, sortable: false, hide: false, align: 'left' },
                    { display: '食堂名称', name: 'NODENAME', width: 70, sortable: false, hide: false, align: 'left' },
                    { display: '餐次', name: 'PERIOD_NAME', width: 50, sortable: false, hide: false, align: 'left' },
					{ display: '名称', name: 'DEPOSITNAME', width: 50, sortable: false, hide: false, align: 'left' },
                    { display: '单价', name: 'Price', width: 100, sortable: false, hide: false, align: 'left' },
                    { display: '数量', name: 'Count', width: 70, sortable: false, hide: false, align: 'left' },
                    { display: '金额', name: 'ConMoney', width: 100, sortable: false, hide: false, align: 'left' },
                    { display: '操作人', name: 'OperatorID', width: 80, sortable: false, hide: false, align: 'left' }
				],
                buttons: [
                            { name: 'Add', displayname: "新增", title: "新增", bclass: 'add', onpress: toolbarItemAdd_onclick },
                            { name: 'Edit', displayname: "修改", title: "修改", bclass: 'edit', onpress: toolbarItemEdit_onclick },
                            { name: 'Delete', displayname: "删除", title: "删除", bclass: 'delete', onpress: toolbarItemDel_onclick },
							{ separator: true }
						 ],
                title: false,
                singleselected: false,
                usepager: true,
                resizable: true,
                page: 1, //默认当前页  
                total: 1, //总页面数  
                useRp: true, //是否可以动态设置每页显示的结果数  
                rp: 20, // 每页默认的结果数  
                rpOptions: [10, 15, 20], //可选择设定的每页结果数
                showcheckbox: true,
                selectedonclick: true,
                rowbinddata: true,
                query: $("#StartTime").val() + ',' + $("#EndTime").val() + ',' + $("#MacID").val() + ',' + $("#PeriodCode").val() + ',' + $("#DepositTypeID").val(),
                hideOnSubmit: true, //隐藏提交  
                autoload: true
            };
            $("#ManualEntryList").flexigrid(option);

            $("#butfind").click(function (e) {
                var vst = $("#StartTime").val();
                var vet = $("#EndTime").val();
                var vmacid = $("#MacID").val();
                var vpc = $("#PeriodCode").val();
                var vdt = $("#DepositTypeID").val();
                option.query = vst + ',' + vet + ',' + vmacid + ',' + vpc + ',' + vdt;
                option.newp = 0;
                $('#ManualEntryList').flexOptions(option).flexReload();
            });
            function toolbarItemAdd_onclick(cmd, grid) {
                OpenModelWindow('@Url.Action("ManualEntryAdd")',
                 { width: 650, height: 300, caption: "新增", onclose: refresh });
            }
            function toolbarItemEdit_onclick(cmd, grid) {
                var items = $("#ManualEntryList").getSelectedRows();
                if (items.length == 0) {
                    showLoadingMsg("请选择要修改的数据!", { left: 400, top: 6 }, true, 3000);
                    return false;
                }
                if (items.length > 1) {
                    showLoadingMsg("只能选择一条要修改的数据!", { left: 400, top: 6 }, true, 3000);
                    return false;
                }
                var ID = items[0][0];
                OpenModelWindow('@Url.Action("ManualEntryEdit")?id=' + ID,
                 { width: 650, height: 300, caption: "修改", onclose: refresh });
            }
            function toolbarItemDel_onclick(cmd, grid) {
                var items = $("#ManualEntryList").getSelectedRows();
                if (items.length == 0) {
                    showLoadingMsg("请选择要删除的数据!", { left: 400, top: 6 }, true, 3000);
                    return false;
                }
                if (!confirm("确定要删除这条数据吗？")) {
                    return false;
                }
                var rowcount = 0;
                for (var i = 0; i < items.length; i++) {
                    var ID = items[i][0];
                    $.ajax({
                        type: "POST",
                        url: '@Url.Action("DeleteManualEntry")',
                        data: { ID: ID },
                        dataType: "json",
                        async: false,
                        success: function (data) {
                            if (data) {
                                rowcount = rowcount + data;
                            }
                        },
                        error: function () { }
                    });
                }
                refreshGrid();
                showLoadingMsg("共有" + rowcount.toString() + "条数据被删除!", { left: 400, top: 6 }, true, 3000);
            }
            function refreshGrid() {
                $("#ManualEntryList").flexReload();
            }
            function refresh() {
                showLoadingMsg("保存成功", { left: 200, top: 6 }, true, 3000);
                $("#ManualEntryList").flexReload();
            }
        });
    </script>
}
<div id="container_sx">
    <div id="mainContent">
        <div id="findDiv">
            <table>
                <tr>
                    <td style="text-align: right;">
                        开始日期:
                    </td>
                    <td style="text-align: left;">
                        @Html.TextBox("StartTime", DateTime.Now.Date.ToString("yyyy-MM-dd"), new { @ReadOnly = true })
                    </td>
                    <td style="text-align: right;">
                        结束日期:
                    </td>
                    <td style="text-align: left;">
                        @Html.TextBox("EndTime", DateTime.Now.Date.ToString("yyyy-MM-dd"), new { @ReadOnly = true })
                    </td>
                    <td style="text-align: right;">
                        食堂名称:
                    </td>
                    <td style="text-align: left;">
                        @Html.DropDownList("MacID", ViewData["MacID"] as IEnumerable<SelectListItem>,
                                 new { @style = "width:110px; height:22px; font-size:13px;" })
                    </td>
                </tr>
                <tr>
                    <td style="text-align: right;">
                        餐次:
                    </td>
                    <td style="text-align: left;">
                        @Html.DropDownList("PeriodCode", ViewData["PeriodCode"] as IEnumerable<SelectListItem>,
                                 new { @style = "width:110px; height:22px; font-size:13px;" })
                    </td>
                    <td style="text-align: right;">
                        名称:
                    </td>
                    <td style="text-align: left;">
                        @Html.DropDownList("DepositTypeID", ViewData["DepositTypeID"] as IEnumerable<SelectListItem>,
                                 new { @style = "width:110px; height:22px; font-size:13px;" })
                    </td>
                    <td colspan="2">
                        <a id="butfind" class="button" href="javascript:void(0);"><span>查询</span></a>
                    </td>
                </tr>
            </table>
        </div>
        <table id="ManualEntryList" style="display: none;">
        </table>
    </div>
</div>
